package org.sy.lab.Java7并发编程实战.五ForkJoin框架.五取消任务;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ForkJoinTask;

public class TaskManager {
	private List<ForkJoinTask<Integer>> tasks;
	public TaskManager() {
		tasks = new ArrayList<>();
	}
	public void addTask(ForkJoinTask<Integer> task) {
		tasks.add(task);
	}
	public void cancelTasks(ForkJoinTask<Integer> cancelTask) {
		for(ForkJoinTask<Integer> task : tasks) {
			if(task != cancelTask) {
				task.cancel(true);
				((SearchNumberTask)task).writeCancelMessage();
			}
		}
	}
}
